import {CLEARSUGGESTION, SETSEARCHRESULT, SETSUGGESTIONLIST} from "@/store/actionTypes";

const initState = {
  suggestion: [],
  searchResults: {
    results: []
  }
}

const searchReducer = (state = initState, action) => {
  switch (action.type) {
    case SETSUGGESTIONLIST:
      return {
        ...state,
        suggestion: action.payload.filter(item => item)
      }

    case CLEARSUGGESTION:
      return {
        ...state,
        suggestion: []
      }

    case SETSEARCHRESULT:
      return {
        ...state,
        searchResults: action.payload
      }
    default:
      return state
  }
}

export default searchReducer
